//
//  SinaWelcomeViewController.swift
//  SinaWeibo
//
//  Created by 王朝阳 on 2016/10/27.
//  Copyright © 2016年 wangzhaoyang. All rights reserved.
//

import UIKit
import SDWebImage

class SinaWelcomeViewController: UIViewController {

    override func loadView() {
        view = bgImage
    }
    
    //MARK: - 欢迎界面动画
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        self.headImage.snp_makeConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
        //设置阻尼动画
        UIView.animate(withDuration: 1, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { 
            self.view.layoutIfNeeded()
            }) { (_) in
                
                UIView.animate(withDuration: 0.25, animations: {
                    self.messageLabel.alpha = 1
                    }, completion: { (_) in
                        //发送切换跟控制的通知
                     NotificationCenter.default.post(name: NSNotification.Name(rawValue: SinaSwitchRootVCNoti), object: "welcomeVC")
                })
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()
    }
    
    //MARK: - 设置视图
    private func setupUI() {
        //1.添加控件
        view.addSubview(headImage)
        view.addSubview(messageLabel)
        
        //2.添加约束
        headImage.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view)
            make.top.equalTo(headImage.snp_bottom).offset(16)
        }
        
    }
    
    //MARK: - 懒加载控件
    //背景图片
    private lazy var bgImage: UIImageView = UIImageView(imgName: "ad_background")
    //用户头像
    private lazy var headImage: UIImageView = {
        let img = UIImageView()
        img.layer.borderColor = SinaColor.cgColor
        img.layer.borderWidth = 1
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        img.hm_setImage(withUrlString: SinaUserAccountViewModel.sharedTools.userAccountModel?.avatar_large, placeholderImgName: "avatar_default_big")
        return img
    }()
    //欢迎回来
    private lazy var messageLabel: UILabel = {
       
        let lab = UILabel(text: "欢迎回来", fontSize:  SinaBigFontSize, textColor: SinaColor)
        lab.textAlignment = .center
        lab.alpha = 0
        return lab
    }()
}
